import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    redirect: "/login"
  },
  {
    path: "/login",
    name: 'login',
    component: () => import('../views/login.vue'),
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home.vue'),
    redirect: "/jichu",
    children: [
      {
        path: "/tushu",
        name: 'tushu',
        component: () => import('../views/tushu/tushu.vue'),
      }, {
        path: "/guoji",
        name: 'guoji',
        component: () => import('../views/guoji/guoji.vue'),
      },
      {
        path: "/jichu",
        name: 'jichu',
        component: () => import('../views/jichu/jichu.vue'),
      },
      {
        path: "/xuan",
        name: 'xuan',
        component: () => import('../views/xuan/xuan.vue'),
      }
    ]
  }
]
const router = new VueRouter({
  routes,
})
router.beforeEach((to, from, next) => {
  if (localStorage.getItem("token")) {
    next();
  } else {
    if (to.path == "/login") {
      next();
    } else {
      next("/login")
    }
  }
})
export default router